package top.milkbox.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import top.milkbox.domain.Collection;
import top.milkbox.service.CollectionService;
import top.milkbox.mapper.CollectionMapper;
import org.springframework.stereotype.Service;

/**
* @author xiaoguo
* @description 针对表【tb_collection】的数据库操作Service实现
* @createDate 2022-05-16 14:56:53
*/
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collection>
    implements CollectionService{

    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public Integer selectCountByMenuId(Integer menuId) {
        QueryWrapper<Collection> wrapper = new QueryWrapper<>();
        wrapper.eq("menu_simple_id", menuId);
        Long count = collectionMapper.selectCount(wrapper);
        return count.intValue();
    }

    @Override
    public Boolean isCollection(Integer userId, Integer menuId) {
        QueryWrapper<Collection> wrapper = new QueryWrapper<>();
        wrapper.eq("userinfo_id", userId);
        wrapper.eq("menu_simple_id", menuId);
        return collectionMapper.selectOne(wrapper) != null;
    }
}




